package br.com.timecardforpeon.sqlite;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import br.com.timecardforpeon.domain.Day;
import br.com.timecardforpeon.domain.Entry;

public class TimeCard4PeonSQLiteOpenHelper extends SQLiteOpenHelper {

	private static final String DATABASE_NAME = "timeCard4Peon.db";
	private static final int DATABASE_VERSION = 1;

	public TimeCard4PeonSQLiteOpenHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase database) {
		database.execSQL(Day.createTable());
		database.execSQL(Entry.createTable());
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

		Log.w(TimeCard4PeonSQLiteOpenHelper.class.getName(),
				String.format(
						"Upgrading database from version %s to %s, which will destroy all old data",
						oldVersion, newVersion));

		db.execSQL("DROP TABLE IF EXISTS day");
		db.execSQL("DROP TABLE IF EXISTS entry");

		this.onCreate(db);
	}
}